#pragma once
#include "mkvstreamvideo.hpp"
#include "mpegparser/M2VParser.h"
#include "mkvcontext.hpp"
#include <vector>
//#include <list>

namespace MkvMux
{

class MkvStreamVideoMpeg2 : public MkvStreamVideo
{
    MkvStreamVideoMpeg2(const MkvStreamVideoMpeg2&);
    MkvStreamVideoMpeg2& operator=(const MkvStreamVideoMpeg2&);
    
public:

    MkvStreamVideoMpeg2(MkvContext&, const BYTE*, ULONG);
    
    HRESULT Write(IMediaSample*);
    int EndOfStream();

protected:

    void WriteTrackName();
    void WriteTrackCodecID();
    void WriteTrackCodecPrivate();
    void WriteTrackCodecName();
    void WriteTrackSettings();

private:
    
    typedef std::vector<BYTE> bytes_t;
    bytes_t m_hdr;

    M2VParser m_parser;    
    
    void WriteFrame(MPEGFrame*);
    //void NewCluster(MPEGFrame*);

    //This is a running count of the frames in the
    //most recent cluster created.  It's needed 
    //to mark the block number, which is used later
    //when creating the cues for the cluster.
    //LONG m_cFrames;    
    
    //typedef std::list<MPEGFrame*> frames_t;
    //frames_t m_frames;
    
   class VideoFrame : public MkvContext::VideoFrame
   {
      VideoFrame(const VideoFrame&);
      VideoFrame& operator=(const VideoFrame&);
      
   private:
      MPEGFrame* const m_pFrame;
   
   public:
      explicit VideoFrame(MPEGFrame*);
      ~VideoFrame(); 
      
      Type type() const;
      
      ULONG size() const;
      const BYTE* data() const;

      ULONG curr_timecode_ms() const;
      SHORT prev_timecode_ms() const;
      SHORT next_timecode_ms() const;
   };
   
};

}  //end namespace MkvMux
